<template>
	<view class="uni_box login">
		<navbar :title='title' :isback="false">
		</navbar>
		<view class="content">
			<!-- <view class="contenthead" @click="showyuyan = true">
				<image src="/static/yanxuan.png" mode="" class="yanxuan right"/>
				<text>{{yuyan}}</text>
				<image src="/static/xia.png" mode="" class="xia"/>
			</view> -->
			<view class="logoview">
				<image src="/static/newlogo.png" mode="" class="lotou"/>
				<text class="biaoti">{{$t('i.hytit')}}</text>
			</view>
			
			<view class="listitem">
				<u-input style="width:78%;" v-model="email" type="text" :border="border" :placeholder='qshuru' />
			</view>
			<view class="listitem" v-if="!isyanzheng">
				<u-input v-model="password" :type="type" :border="border" :password-icon="passwordIcon" :placeholder='qingmi' />
			</view>
			<view class="zhuce">
				<text class="zhuceitem"><text class="zhuces" @click="routerTo('/pages/login/wangMima')">{{$t('common.loginwm')}}</text></text>
				<text class="wangji" @click="routerTo('/pages/login/newregister')">{{$t('common.loginzc')}}</text>
			</view>
			<view class="bot">
				<view class="botbtn" @click="login">
					<view class="btnbgview">
						{{$t('common.logintit')}}
					</view>
				</view>
				<view class="shenqing" @click="getjiechu">
					<text>{{$t('i.jiechu')}}</text>
				</view>
			</view>
			<view class="item_desc">
				<u-checkbox 
					@change="checkboxChange" 
					v-model="checked"
					active-color='#8A1596'
					icon-size='10'
					label-size='24'
					size='26'
				>
				<view class="desctext">
					{{$t('common.loginmiao')}}
					<text style="color: #8A1596;" @click.stop="routerTo('/pages/my/yhXieyi?key=agreement')">《{{$t('common.yhxy')}}》</text>{{$t('common.and')}}
					<text style="color: #8A1596;" @click.stop="routerTo('/pages/my/yhXieyi?key=register')">《{{$t('common.ysxy')}}》</text>
				</view>
				</u-checkbox>
			</view>

			
			
		</view>
		<u-toast ref="uToast" />
		<u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
		<u-action-sheet :list="yuyanlist" v-model="showyuyan" @click="actionSheetCallbackyuyan"></u-action-sheet>
	</view>
</template>
<!-- <script src="https://cdn.bootcss.com/babel-polyfill/7.4.3/polyfill.min.js"></script>
<script src="https://www.yunpian.com/static/official/js/libs/riddler-sdk-0.2.2.js?t=20210720"></script> -->
<script>
	
	export default {
		data() {
			return {
				email: "",
				password: "",
				isyanzheng:false,
				checked:false,
				timer: null,
				time: 60,
				isTimer: false,
				iseyes:false,
				type_number: "text",
				type_password: "password",
				code:'',
				value: '',
				type: 'password',
				passwordIcon: true,
				border: false,
				show: false,
				// actionSheetList: [
				// 	{
				// 		text: '163邮箱'
				// 	},
				// 	{
				// 		text: 'QQ邮箱'
				// 	}
				// ],
				// yuyanlist: [
				// 	{
				// 		text: '简体中文'
				// 	},
				// 	{
				// 		text: '英文'
				// 	}
				// ],
				// actext:'可选邮箱',
				showyuyan:false,
				yuyan:'简体中文'

			}
		},
		computed: {
			// 正确用法
			actext:{
				get(){
                    return this.$t('common.kexuan')
                },
                set(v) {
                    return v
                }
			},
			title(){
				return this.$t('common.logintit')
			},
			actionSheetList(){
				let datas =[
					{
						text: this.$t('common.youone')
					},
					{
						text: this.$t('common.youtwo')
					}
				]
				return datas
			},
			yuyanlist(){
				let datas =[
					{
						text: '简体中文'
					},
					{
						text: 'English'
					}
				]
				return datas
			},
			qshuru(){
				return this.$t('i.yx')
			},
			qingmi(){
				return this.$t('i.mi')
			}
			// yuyan(){
			// 	return this.$t('common.zh')
			// }
		},
		onLoad(){
		},
		onReachBottom: function() {},
		methods: {
			async login() {
				if (!this.email) {
					this.$u.toast(this.$t('i.yx'));
					return false;
				}
				if (!this.password) {
					this.$u.toast(this.$t('i.dengmi'));
					return false;
				}
				if (!this.checked) {
					this.$u.toast(this.$t('i.qxie'));
					return false;
				}
				let data = await this.$u.api.login({
					email: this.email,
					password: this.password
				});
				console.log(data)
				this.$store.commit('changeToken', data.token);
				this.$u.toast(this.$t('new.qdeng'));
				
				setTimeout(() => {
					this.router('/pages/tabbar/Tabhome')
					// uni.switchTab({
					// 	url: '/pages/tabbar/Tabhome'
					// })
				}, 1000);
			},
			async lockSheet() {
				let phone = this.phone;
				if (!phone) {
					this.$refs.uToast.show({
						title: this.$t('new.qshou'),
						type: "error"
					})
					return
				};
				// this.initYpRiddler()
				// this.$refs.captcha.initYpRiddler();
				this.$refs.captcha.verify();
			},
			async handleCaptcha(validate) {
				this.isTimer = true;
				this.timer = setInterval(() => {
					this.time--
					if (this.time < 0) {
						this.isTimer = false;
						this.time = 60;
						clearInterval(this.timer);
					};
				}, 1000);
				let res = await this.$u.api.smsSend({
					phone: this.phone,
					scene: "login",
					authenticate:validate.authenticate,
					token:validate.token
				});
			},
			backTo() {
				uni.navigateBack()
			},
			routerTo(url) {
				uni.navigateTo({
					url
				})
			},
			router(url) {
				uni.redirectTo({
					url
				})
				// uni.navigateTo({
				// 	url
				// })
			},
			checkboxChange(e) {
				console.log(e);
				this.checked = e.value
				console.log(this.checked)
			},
			// 选中任一checkbox时，由checkbox-group触发
			checkboxGroupChange(e) {
				console.log(e);
			},
			headclick(e){
				this.isyanzheng = e
			},
			eyesClick(){
				this.iseyes = !this.iseyes
				
				console.log(this.iseyes)
			},
			actionSheetCallback(e){
				// console.log(e)
				this.actext = this.actionSheetList[e].text
				if(this.actionSheetList[e].text == '163邮箱'){
					this.email = this.email+'@163.com'
				}else if(this.actionSheetList[e].text == 'QQ邮箱'){
					this.email = this.email+'@qq.com'
				}
			},
			actionSheetCallbackyuyan(e){
				this.yuyan = this.yuyanlist[e].text
				if(e == 0){
					this.switchLang('zh')
				}else if(e == 1){
					this.switchLang('en')
				}else if(e == 2){
					this.switchLang('th')
				}
			},
			switchLang(e){
				this.$i18n.locale = e
				uni.setStorageSync('locale',e)
			},
			getjiechu(){
				console.log("++++")
				this.routerTo('/pages/my/jiefeng')
			}
		}
	};
</script>

<style scoped lang="scss">
	page{
		background-color: #fff;
	}
	.login {
		.slot_right {
			display: flex;
			align-items: center;

			.nav_img {
				width: 48rpx;
				height: 48rpx;
				margin-right: 26rpx;
			}
		}

		.content {
			padding: 30rpx 35rpx 0;
			box-sizing: border-box;
			.contenthead{
				display: flex;
				flex-direction: row;
				align-items: center;
				.right{
					margin-left: auto;
				}
				.yanxuan{
					width: 28rpx;
					height: 28rpx;
					margin-right: 10rpx;
				}
				.xia{
					width: 17rpx;
					height: 13rpx;
					margin-left: 8rpx;
					position: relative;
					top: 5rpx;
				}
				.ltext{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}

			}
			.lotou{
				width: 150rpx;
				height: 150rpx;
				margin: 30rpx 0 40rpx;
			}
			.biaoti{
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
			.ltext{
				font-size: 50rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				display: block;
				margin-bottom: 70rpx;
			}
			.zhangnav{
				width: 360rpx;
				margin: 0 auto 40rpx;
				display: flex;
				flex-direction: row;
				.zhangnavitem{
					width: 50%;
					display: flex;
					flex-direction: column;
					align-items: center;
					.xian{
						width: 100%;
						height: 4rpx;
						background: #999999;
					}
					.tit{
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						display: inline-block;
						margin-bottom: 8rpx;
					}
					
				}
				.active .xian{
					background: #73FAB5;
				}
				.active .tit{
					color: #73FAB5;
					font-weight: bold;
				}
			}
			.listitem{
				width: 100%;
				height: 100rpx;
				border: 1rpx solid #C8C9D1;
				border-radius: 10rpx;
				padding: 0 35rpx;
				margin-bottom: 36rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				.qu{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					margin-right: 20rpx;
				}
				.iteminput{
					font-size: 28rpx;
					color: #fff;
					width: 70%;
					height: 70%;
					background: #222222;
					border: none;
				}
				.iteminput:active{
					border: none;
				}
				.iteminput:focus {
				    outline:none;
				    border: none;
				}
				.yanright{
					margin-left: auto;
					display: flex;
					align-items: center;
				}
				.fayan{
					margin-left: auto;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #73FAB5;
				}
				.yan{
					// margin-left: auto;
					width: 44rpx;
					height: 44rpx;
				}
				.youitem{
					display: flex;
					flex-direction: row;
					width: 22%;
					height: 70%;
					justify-content: flex-end;
					align-items: center;
					.youitems{
						// width:50%;
						padding: 0px 8px;
						background: #2A64E4;
						color: #fff;
						font-size: 11px;
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: center;
						border-radius: 7px;
						margin-left: 5px;
					}
					.xia{
						width:17rpx;
						height:13rpx;
						margin-left:10rpx;
					}
					.youtext{
						color:#333;
						font-size:25rpx;
					}
				}
			}
            .zhuce{
				display: flex;
				flex-direction: row;
				
				.zhuceitem{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
				}
				.wangji{
					margin-left: auto;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}
			// 按钮样式开始
			.bot{
				margin-top: 100rpx;
				.botbtn{
					width: 100%;
					height: 88rpx;
					position: relative;
					background: #8A1596;
					border-radius: 10rpx;

					.btnbg{
						width: 100%;
						height: 100%;
						position: absolute;
						z-index: 0;
					}
					.btnbgview{
						position: relative;
						z-index: 1;
						width: 100%;
						height: 100%;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
					}
				}
			}
			// 按钮样式结束
			.item_desc{
				margin-top: 36rpx;
				display: flex;
				align-items: center;
				.desctext{
					display: flex;
					align-items: center;
					color:#999;
					font-size: 26rpx;
				}
			}
		}
	}
	.logoview{
		display: flex;
		align-items: center;
		justify-content: center;
		margin:40rpx 0 100rpx;
		flex-direction: column;
	}
	.shenqing{
		margin-top: auto;
		display: flex;
		align-items: center;
		justify-content: center;
		// position: fixed;
		// bottom: 10rpx;
		position: relative;
		width: 100%;
		margin: 30rpx 0;
		text{
			color: rgb(138, 21, 150);
			font-size: 28rpx;
			font-weight: 400;
			display: block;
			text-align: center;
		}
	}
</style>
